<?php

	class db {
		var $host = 'raulsanchez.com.ar';
		var $user = 'raulsanc_syncrol';
		var $pass = 's8qun9i6sa';
		var $database = 'raulsanc_syncrolist';
		var $port = '';

		var $conn;
		
		public function connect() {
			
			if (!$this->conn){
				$this->conn = mysql_connect($this->host.$this->port, $this->user, $this->pass) or 
				die('No se pudo conectar : ' . mysql_error());
			}
			mysql_select_db($this->database, $this->conn) or 
			die("No se pudo conectar con la base de datos " . $this->database);
		}
		
		public function disconnect() {
			mysql_close($this->conn);
		}

		public function query($sql) {
		  	$rs = mysql_query($sql);

			if($rs) {
			    $records = mysql_num_rows($rs);
			    $res = array();
			    
			    for($i=0;$i<$records;$i++) 
			    	$res[$i] = mysql_fetch_assoc($rs);
			    
			    if (count($res) > 0)
			    	return $res;
			    else
			    	return 0;
			}
			else
			    return 0;
		}

		public function delete($sql) {
		  	return mysql_query($sql);
		}

		public function update($sql)
		{
			$sql = str_replace("0,","NULL,",$sql);

			return mysql_query($sql);
		}

		public function insert($sql)
		{
			$sql = str_replace("0,","NULL,",$sql);

			$res_id = 0;

			$rs = mysql_query($sql);
			if ($rs) 
				$res_id = mysql_insert_id(); // id
			else 
				// Error al crear 
				$res_id = 0;

			return $res_id;
		}
		
	} // class
